package com.saihai.jiankang.zzjg.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.saihai.common.core.domain.entity.UfZzjgTree;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.saihai.common.annotation.Log;
import com.saihai.common.core.controller.BaseController;
import com.saihai.common.core.domain.AjaxResult;
import com.saihai.common.enums.BusinessType;
import com.saihai.jiankang.zzjg.domain.UfZzjg;
import com.saihai.jiankang.zzjg.service.IUfZzjgService;
import com.saihai.common.utils.poi.ExcelUtil;
import com.saihai.common.core.page.TableDataInfo;

/**
 * 组织架构Controller
 *
 * @author hzn
 * @date 2024-07-01
 */
@RestController
@RequestMapping("/jiankang/zzjg")
public class UfZzjgController extends BaseController {
    @Autowired
    private IUfZzjgService ufZzjgService;

    /**
     * 查询组织架构列表
     */
    @GetMapping("/list")
    public TableDataInfo list(UfZzjg ufZzjg) {
        List<UfZzjg> list = ufZzjgService.selectUfZzjgList(ufZzjg);
        return getDataTable(list);
    }


    @GetMapping("/zzjgTree")
    public AjaxResult deptTree(UfZzjgTree ufZzjgTree) {
        if (ufZzjgTree.getId() ==9999999) {
            ufZzjgTree.setId(null);
        }
        return success(ufZzjgService.selectUfZzjgTreeList(ufZzjgTree));
    }


    /**
     * 查询学校
     */
    @GetMapping("/selectSchool")
    public TableDataInfo selectSchool(UfZzjg ufZzjg) {
        List<UfZzjg> list = ufZzjgService.selectSchool(ufZzjg);
        return getDataTable(list);
    }

    /**
     * 导出组织架构列表
     */
    @PreAuthorize("@ss.hasPermi('zzjg:zzjg:export')")
    @Log(title = "组织架构", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UfZzjg ufZzjg) {
        List<UfZzjg> list = ufZzjgService.selectUfZzjgList(ufZzjg);
        ExcelUtil<UfZzjg> util = new ExcelUtil<UfZzjg>(UfZzjg.class);
        util.exportExcel(response, list, "组织架构数据");
    }

    /**
     * 获取组织架构详细信息
     */
    @PreAuthorize("@ss.hasPermi('zzjg:zzjg:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(ufZzjgService.selectUfZzjgById(id));
    }

    /**
     * 新增组织架构
     */
    @PreAuthorize("@ss.hasPermi('zzjg:zzjg:add')")
    @Log(title = "组织架构", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UfZzjg ufZzjg) {
        return toAjax(ufZzjgService.insertUfZzjg(ufZzjg));
    }

    /**
     * 修改组织架构
     */
    @PreAuthorize("@ss.hasPermi('zzjg:zzjg:edit')")
    @Log(title = "组织架构", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UfZzjg ufZzjg) {
        return toAjax(ufZzjgService.updateUfZzjg(ufZzjg));
    }

    /**
     * 删除组织架构
     */
    @PreAuthorize("@ss.hasPermi('zzjg:zzjg:remove')")
    @Log(title = "组织架构", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(ufZzjgService.deleteUfZzjgByIds(ids));
    }
}
